<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <script src="../js/vue-router_3.0.2.js"></script>

</head>
<body>
<div id="div1">
    <router-link to="/users" >用户模块</router-link>
    <router-link to="/products1" >商品模块1</router-link>
    <!-- 占位符: 显示点击的组件对应的模板内容 -->
    <router-view></router-view>    <!--占位符，会被routes数组里面的component代替-->
</div>
<script>
    const user_con = {
        template: '<h1>用户模块</h1>'
    }

    const products1 = {
        template: '<h1>商品模块1</h1>'
    }

    const products2 = {
        template: '<h1>商品模块2</h1>'
    }

    // 创建路由对象
    const router = new VueRouter({
        /*
          配置路由规则
            通过path来映射 路径 -> 组件

            重定向：当前A路径的时候，显示B路径对应的内容

            /  当什么都不点击的时候，可以用来做初始化显示
         */
        routes: [
            {path: '/', redirect: '/users'},
            {path: '/users', component: user_con},
            {path: '/products1', redirect: '/products2'},
            {path: '/products2', component: products2}
        ]
    })

    const vm = new Vue({
        el: '#div1',
        data: {},
        // 挂载路由对象
        // router:router 写法一
        router

    })
</script>
</body>
</html>